package alex.cicy.lambda.syntax;

import java.io.FileFilter;
import java.util.*;
import java.util.function.IntBinaryOperator;
import java.util.stream.Stream;

/**
 * Created by picago on 2015/8/3.
 */
public class Expression01 {

    public void test() {

    }

    public static void main(String[] args) {
        IntBinaryOperator addTwo = (int x, int y) -> x+y;
        System.out.println(addTwo);

        new Thread(() -> {
            FileFilter fileFilter = f -> f.getName().startsWith("A");
            System.out.println("run in new thread.." + fileFilter);
        }).start();

        List<Long> longs = new ArrayList<>();
        longs.add(1000L);
        longs.add(2000L);
        Stream<Long> filtered = longs.stream().filter(l -> l > 1000);
        System.out.println(filtered.map(l->l));

        // Method References
        Person[] persons = new Person[]{new Person("Alex", 27), new Person("Cicy", 28)};
        Comparator<Person> byName = Comparator.comparing(p -> p.getName());
        byName = Comparator.comparing(Person::getName);
        Arrays.sort(persons, byName);

        System.out.println(byName);
        System.out.println(persons);
        Arrays.asList(persons).sort(Comparator.comparing(Person::getName).reversed());
        System.out.println(Arrays.toString(persons));

        System.out.println("我们的爱若是错如 ");
    }

    static class Person {
        private final String name;
        private final int age;

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }

        public Person(String name, int age) {
            this.name = name;
            this.age = age;
        }
    }
}
